//
//  RootViewController.m
//  BlueTDevice
//
//  Created by MingmingSun on 16/8/20.
//  Copyright © 2016年 Sunmingming. All rights reserved.
//

#import "RootViewController.h"
#import "WodeViewController.h"
#import "ZhuyeViewController.h"
#import "BasicViewController.h"
#import "ShangchengViewController.h"
#import "HuatiViewController.h"

@interface RootViewController ()<UITabBarControllerDelegate>

@property(nonnull,strong) BasicViewController* c1;
@property(nonnull,strong) HuatiViewController* c2;
@property(nonnull,strong) ZhuyeViewController* c3;
@property(nonnull,strong) ShangchengViewController* c4;
@property(nonnull,strong) WodeViewController* c5;

@end

@implementation RootViewController

@synthesize c1,c2,c3,c4,c5;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.delegate = self;
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.c1= [BasicViewController new];
        c1.tabBarItem.title=@"锻炼";
        c1.tabBarItem.image=[UIImage imageNamed:@"tab1"];
        
        self.c2=[[HuatiViewController alloc]init];
        c2.view.backgroundColor=[UIColor brownColor];
        c2.tabBarItem.title=@"话题";
        c2.tabBarItem.image=[UIImage imageNamed:@"tab2"];
        
        self.c3=[[ZhuyeViewController alloc]init];
        c3.tabBarItem.title=@"动态";
        c3.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];
        
        self.c4=[[ShangchengViewController alloc]init];
        c4.tabBarItem.title=@"商城";
        c4.tabBarItem.image=[UIImage imageNamed:@"tab4"];
        
        self.c5=[WodeViewController new];
        c5.tabBarItem.title=@"我的";
        c5.tabBarItem.image=[UIImage imageNamed:@"tab5"];
        
        self.viewControllers=@[c1,c2,c3,c4,c5];
        self.selectedIndex = 0;
        self.title = [[[self.viewControllers objectAtIndex:self.selectedIndex] tabBarItem] title];
        self.tabBar.tintColor = TitleGreen;
        [self.tabBar configureFlatTabBarWithColor:[UIColor whiteColor] selectedColor:[UIColor whiteColor]];
        
        UIButton *tabButton = [[UIButton alloc] initWithFrame:CGRectMake(kDeviceWidth/2-27,KDeviceHeight - 64 - 54, 54, 54)];
        [tabButton setImage:[UIImage imageNamed:@"button_main"] forState:UIControlStateNormal];
        [tabButton addTarget:self action:@selector(tabPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:tabButton];
    }
    return self;
}

-(void)tabPressed:(id)sender{
    NSLog(@"fff");
    self.selectedIndex = 2;
    self.title = [[self.tabBar.items objectAtIndex:2] title];
}

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    self.title = item.title;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.rightBarButtonItem = nil;
    /*
    if(viewController == self.c1){
        self.title = @"未连接设备";
    }else if(viewController == self.c2){
        self.title = @"未连接设备";
        
    }else if(viewController == self.c3){
        self.title = @"未连接设备";
        
    }else if(viewController == self.c4){
        self.title = @"关于";
        
    }else if(viewController == self.c5){
        self.title = @"未连接设备";
    }*/
    return true;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
